From 190c7f7736de0715fa02cff0cdaae4e12f247bc6 Mon Sep 17 00:00:00 2001 From: tsteven4 Date: Fri, 9 Aug 2013 23:47:33 +0000 Subject: [PATCH] fix memory leaks in coto, geoniche, humminbird, xol. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4527 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/coto.cc | 11 ++++++++--- gpsbabel/geoniche.cc | 3 ++- gpsbabel/humminbird.cc | 2 ++ gpsbabel/xol.cc | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/gpsbabel/coto.cc b/gpsbabel/coto.cc index 99956abcb..b91be5d83 100644 --- a/gpsbabel/coto.cc +++ b/gpsbabel/coto.cc @@ -138,12 +138,17 @@ wr_init(const char* fname) static void wr_deinit(void) { + // pdb_close() will only free appinfo in read mode, and pdb_create() sets the mode to write. + struct appinfo* ai = (struct appinfo*) file_out->appinfo; pdb_close(file_out); + if (ai) { + free(ai); + } } /* helpers */ -static char* +static QString coto_get_icon_descr(int category, const appinfo_t* app) { char buff[CATEGORY_NAME_LENGTH + 1] = "Not Assigned"; @@ -154,10 +159,10 @@ coto_get_icon_descr(int category, const appinfo_t* app) strncpy(buff, app->categories[category], sizeof(buff) - 1); if (buff[0] == '\0') { - return NULL; + return QString(); } } - return xstrdup(buff); + return QString(buff); } static void diff --git a/gpsbabel/geoniche.cc b/gpsbabel/geoniche.cc index 2c9f4610b..a983ba5bd 100644 --- a/gpsbabel/geoniche.cc +++ b/gpsbabel/geoniche.cc @@ -218,7 +218,7 @@ geoniche_read_asc(void) int id; int route_id; char* title; - char* category; + QString category; double lat, lon, alt; char* datestr, *timestr; int icon; @@ -277,6 +277,7 @@ geoniche_read_asc(void) fatal(MYNAME ": Premature EOD processing field 5 (Category).\n"); } category = p; + xfree(p); /* Field 6: Latitude */ p = field(&vdata, &vlen); diff --git a/gpsbabel/humminbird.cc b/gpsbabel/humminbird.cc index d6584357a..73b078573 100644 --- a/gpsbabel/humminbird.cc +++ b/gpsbabel/humminbird.cc @@ -309,6 +309,7 @@ humminbird_read_wpt(gbfile* fin) // that describes a sub-status switch (w.status) { case 0: // Waypoint not used. So why do we have one? + waypt_free(wpt); break; case 1: // Waypoint permanent. case 2: // Waypoint temporary. @@ -319,6 +320,7 @@ humminbird_read_wpt(gbfile* fin) case 17: // Waypoint group body. case 63: // Waypoint group invalid. default: + waypt_free(wpt); break; } diff --git a/gpsbabel/xol.cc b/gpsbabel/xol.cc index 12eb92d5c..6f9c41c38 100644 --- a/gpsbabel/xol.cc +++ b/gpsbabel/xol.cc @@ -100,7 +100,7 @@ xol_shape(const char *args, const QXmlStreamAttributes* attrv) } if (attrv->hasAttribute("icon")) { - wpt->icon_descr = xstrdup(attrv->value("icon").toString().toUtf8().constData()); + wpt->icon_descr = attrv->value("icon").toString(); } } } -- 2.30.2